﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace pwestcott.Util.Tests.Essence.Equals
{
    [TestFixture]
    public class EqualsFieldValueTests
    {
        [EssenceClass(UseIn = EssenceFunctions.All)]
        class TestEssence : IEquatable<TestEssence>
        {
            [Essence] public int MyInt;

            public bool Equals(TestEssence other)
            {
                return Essence<TestEssence>.EqualsStatic(this, other);
            }
        }

        class TestManual
        {
            public int MyInt;

            public bool Equals(TestManual other)
            {
                if (!this.MyInt.Equals(other.MyInt))
                    return false;

                return true;
            }
        }

        [Test]
        public void NullNullTest()
        {
            var e1 = new TestEssence();
            var e2 = new TestEssence();
            var m1 = new TestManual();
            var m2 = new TestManual();

            Assert.IsTrue(m1.Equals(m2));
            Assert.AreEqual(m1.Equals(m2), e1.Equals(e2));
        }

        [Test]
        public void QBFNullTest()
        {
            var e1 = new TestEssence();
            var e2 = new TestEssence();
            var m1 = new TestManual();
            var m2 = new TestManual();

            e1.MyInt = m1.MyInt = 42;

            Assert.IsFalse(m1.Equals(m2));
            Assert.AreEqual(m1.Equals(m2), e1.Equals(e2));
        }

        [Test]
        public void NullQBFTest()
        {
            var e1 = new TestEssence();
            var e2 = new TestEssence();
            var m1 = new TestManual();
            var m2 = new TestManual();

            e2.MyInt = m2.MyInt = 42;

            Assert.IsFalse(m1.Equals(m2));
            Assert.AreEqual(m1.Equals(m2), e1.Equals(e2));
        }

        [Test]
        public void QBFQBFTest()
        {
            var e1 = new TestEssence();
            var e2 = new TestEssence();
            var m1 = new TestManual();
            var m2 = new TestManual();

            e1.MyInt = e2.MyInt = m1.MyInt = m2.MyInt = 42;

            Assert.IsTrue(m1.Equals(m2));
            Assert.AreEqual(m1.Equals(m2), e1.Equals(e2));
        }
    }
}
